package com.clone;

import java.io.*;

/**
 * Created by wangyg on 2016/11/10.
 */
public class Clone {
	public static Object depthClone(Object obj) throws IOException, ClassNotFoundException {
		//把对象读进去
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(obj);
		//再从流里面读出来
		ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
		ObjectInputStream os = new ObjectInputStream(is);
		return os.readObject();
	}
}
